package com.example.chatper07;


import org.apache.commons.beanutils.BeanUtils;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;


@WebServlet("/UserLoginDemo")
public class UserLoginDemo extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        User user = new User();
        try {
            BeanUtils.populate(user, request.getParameterMap());

            // Assuming you want to store the user object in the request
            request.setAttribute("loginUser", user);

            // Forward the request to a JSP page for displaying the result
            request.getRequestDispatcher("/loginResult.jsp").forward(request, response);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doGet(req, resp);
    }
}
